# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

# from cnpy import *
# pip3 install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
# pip3 install openpyxl -i https://pypi.tuna.tsinghua.edu.cn/simple

# pip

import pandas as pd

# 读取Excel文件
# df = pd.read_excel('device.xlsx')
df = pd.read_excel('E:\mz\device.xlsx')

# 假设我们要插入到数据库的表名为'your_table_name'
table_name = 'your_table_name'

# 逐行生成SQL INSERT语句
sql_statements = []
for index, row in df.iterrows():
    # 构建SQL语句，这里使用占位符，实际使用时需要根据实际字段名和类型进行调整
    sql = f"INSERT INTO {table_name} (column1, column2, column3) VALUES (%s, %s, %s);"
    values = tuple(row)  # 或者根据实际字段调整，例如：row[['column1', 'column2', 'column3']]
    sql_statements.append((sql, values))

# 打印生成的SQL语句（调试用）
for sql, values in sql_statements:
    print(sql % values)  # 注意：这里使用了%s占位符，所以需要用values元组替换%s

with open("filename.txt", "w") as file:
    for sql, values in sql_statements:
        file.write(sql % values + '\n')
